<?php

class Demo_model extends CI_Model {
	
		/*
	function getAll() {
		$q = $this->db->query("SELECT * FROM data");
		if($q->num_rows() > 0) {
			foreach($q->result() as $row) {
				$data[] = $row;
			}
			return $data;
		}
	}
	*/
	/*
	function getAll() {
		$q = $this->db->get('data');
		
		if($q->num_rows() > 0) {
			foreach ($q->result() as $row) {
				$data[] = $row;
			}
			return $data;
		}
	}
	*/
	
	/*
	function getAll() {
		$this->db->select('title, contents');
		$q = $this->db->get('data');

		if($q->num_rows() > 0) {
			foreach ($q->result() as $row) {
				$data[] = $row;
			}
			return $data;
		}		
	}
	*/
	/*
	function getAll() {
		$sql = "SELECT title, author, contents FROM data WHERE id = ? AND author = ?";
		$q = $this->db->query($sql, array(2, 'Jeffrey Way'));
		
		if($q->num_rows() > 0) {
			foreach ($q->result() as $row) {
				$data[] = $row;
			}
			return $data;
		}		
	}
	*/
	function getAll2() 
	{
		$q = $this->db->query("SELECT * FROM data where id < 1000 and length(content)>1");
		if($q->num_rows() > 0) {
			foreach($q->result() as $row) {
				$data[] = $row;
			}
			return $data;
		}
	}
	
	function getAll()
	{
		$this->db->select('content,create_date');
		$q = $this->db->get('data');
		
		if($q->num_rows() > 0) {
			foreach($q->result() as $row) {
				$data[] = $row;
			}
			return $data;
		}
	}
	
	/*
		2.CRUD OPERATION
	*/
	
	function get_records()
	{
		$query = $this->db->get('data');
		return $query->result();
	}
	
	function add_record($data)
	{
		$this->db->insert('data', $data);
		return;
	}
	
	function update_record($data) 
	{
		$this->db->where('id', $this->uri->segment(3));
		$this->db->update('data', $data);
	}
	
	function delete_record()
	{
		$this->db->where('id', $this->uri->segment(3));
		$this->db->delete('data');
	}
}
?>